/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package attackDetection2;
import java.util.ArrayList;
import java.sql.*;
/**
 *
 * @author john
 */
public class Packet {

    private int index;
    private int nodeId;
    private int nodeIP;
    private String previousNodeIP;
    private String mode;
    private String type;
    private int packetLength;
    private int packetSequenceNumber;
    private int messageId;
    private int messageSize;
    private int messageSequenceNumber;
    private Time timeso;
    private Timestamp timeStamp;
    private int vtime;
    private int sourceNodeIP;
    private String psip;
    private int destinationNodeIP;
    private int nextHopId;
    private int nextHopIP;
    private String pnhip;
    private int previousHopId;
    private int previousHopIP;
    private String pphip;
    private int timeToLive;
    private int hopCount;
    private int nonb; //?????
    private int watchdog;

    public Packet(ResultSet res)
    {
         try {
            setIndex(res.getInt("plogid"));
            setNodeId(res.getInt("nodeid"));
            setNodeIP(res.getInt("nodeip"));
            setMode(res.getString("opmode"));
            setType(res.getString("msgtype"));
            setPacketLength(res.getInt("plength"));
            setPacketSequenceNumber(res.getInt("pseqno"));
            setMessageSize(res.getInt("msgsize"));
            setMessageSequenceNumber(res.getInt("msgseqno"));
            setTimeso(res.getTime("timeso"));
            // Missing unixtimeso
            setTimeStamp(res.getTimestamp("timestamp"));
            // Missing unixtimestampso
            setVtime(res.getInt("vtime"));
            setSourceNodeIP(res.getInt("sip"));
            setDestinationNodeIP(res.getInt("dip"));
            setNextHopId(res.getInt("nexthopid"));
            setNextHopIP(res.getInt("nexthopip"));
            setPreviousHopId(res.getInt("prehopid"));
            setPreviousHopIP(res.getInt("prehopip"));
            setTimeToLive(res.getInt("ttl"));
            setHopCount(res.getInt("hopcount"));
            setNonb(res.getInt("nonb"));
            setWatchdog(res.getInt("watcher"));

        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
    }

    /**
     * @return the index
     */
    public int getIndex() {
        return index;
    }

    /**
     * @param index the index to set
     */
    public void setIndex(int index) {
        this.index = index;
    }

    /**
     * @return the nodeId
     */
    public int getNodeId() {
        return nodeId;
    }

    /**
     * @param nodeId the nodeId to set
     */
    public void setNodeId(int nodeId) {
        this.nodeId = nodeId;
    }

    /**
     * @return the nodeIP
     */
    public int getNodeIP() {
        return nodeIP;
    }

    /**
     * @param nodeIP the nodeIP to set
     */
    public void setNodeIP(int nodeIP) {
        this.nodeIP = nodeIP;
    }

    /**
     * @return the mode
     */
    public String getMode() {
        return mode;
    }

    /**
     * @param mode the mode to set
     */
    public void setMode(String mode) {
        this.mode = mode;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the packetLength
     */
    public int getPacketLength() {
        return packetLength;
    }

    /**
     * @param packetLength the packetLength to set
     */
    public void setPacketLength(int packetLength) {
        this.packetLength = packetLength;
    }

    /**
     * @return the packetSequenceNumber
     */
    public int getPacketSequenceNumber() {
        return packetSequenceNumber;
    }

    /**
     * @param packetSequenceNumber the packetSequenceNumber to set
     */
    public void setPacketSequenceNumber(int packetSequenceNumber) {
        this.packetSequenceNumber = packetSequenceNumber;
    }

    /**
     * @return the messageSize
     */
    public int getMessageSize() {
        return messageSize;
    }

    /**
     * @param messageSize the messageSize to set
     */
    public void setMessageSize(int messageSize) {
        this.messageSize = messageSize;
    }

    /**
     * @return the sourceIP
     */
    public int getSourceIP() {
        return getSourceNodeIP();
    }

    /**
     * @param sourceIP the sourceIP to set
     */
    public void setSourceIP(int sourceIP) {
        this.setSourceNodeIP(sourceIP);
    }

    /**
     * @return the nextHopIP
     */
    public int getNextHopIP() {
        return nextHopIP;
    }

    /**
     * @param nextHopIP the nextHopIP to set
     */
    public void setNextHopIP(int nextHopIP) {
        this.nextHopIP = nextHopIP;
    }

    /**
     * @return the destinationIP
     */
    public int getDestinationIP() {
        return getDestinationNodeIP();
    }

    /**
     * @param destinationIP the destinationIP to set
     */
    public void setDestinationIP(int destinationIP) {
        this.setDestinationNodeIP(destinationIP);
    }

    /**
     * @return the previousHopIP
     */
    public int getPreviousHopIP() {
        return previousHopIP;
    }

    /**
     * @param previousHopIP the previousHopIP to set
     */
    public void setPreviousHopIP(int previousHopIP) {
        this.previousHopIP = previousHopIP;
    }

    /**
     * @return the timeToLive
     */
    public int getTimeToLive() {
        return timeToLive;
    }

    /**
     * @param timeToLive the timeToLive to set
     */
    public void setTimeToLive(int timeToLive) {
        this.timeToLive = timeToLive;
    }

    /**
     * @return the hopCount
     */
    public int getHopCount() {
        return hopCount;
    }

    /**
     * @param hopCount the hopCount to set
     */
    public void setHopCount(int hopCount) {
        this.hopCount = hopCount;
    }

    /**
     * @return the nonb
     */
    public int getNonb() {
        return nonb;
    }

    /**
     * @param nonb the nonb to set
     */
    public void setNonb(int nonb) {
        this.nonb = nonb;
    }

    /**
     * @return the watchdog
     */
    public int getWatchdog() {
        return watchdog;
    }

    /**
     * @param watchdog the watchdog to set
     */
    public void setWatchdog(int watchdog) {
        this.watchdog = watchdog;
    }

    /**
     * @return the messageId
     */
    public int getMessageId() {
        return messageId;
    }

    /**
     * @param messageId the messageId to set
     */
    public void setMessageId(int messageId) {
        this.messageId = messageId;
    }

    /**
     * @return the messageSequenceNum
     */
    public int getMessageSequenceNum() {
        return getMessageSequenceNumber();
    }

    /**
     * @param messageSequenceNum the messageSequenceNum to set
     */
    public void setMessageSequenceNum(int messageSequenceNum) {
        this.setMessageSequenceNumber(messageSequenceNum);
    }

    /**
     * @return the previousNodeIP
     */
    public String getPreviousNodeIP() {
        return previousNodeIP;
    }

    /**
     * @param previousNodeIP the previousNodeIP to set
     */
    public void setPreviousNodeIP(String previousNodeIP) {
        this.previousNodeIP = previousNodeIP;
    }

    /**
     * @return the messageSequenceNumber
     */
    public int getMessageSequenceNumber() {
        return messageSequenceNumber;
    }

    /**
     * @param messageSequenceNumber the messageSequenceNumber to set
     */
    public void setMessageSequenceNumber(int messageSequenceNumber) {
        this.messageSequenceNumber = messageSequenceNumber;
    }

    /**
     * @return the timeso
     */
    public Time getTimeso() {
        return timeso;
    }

    /**
     * @param timeso the timeso to set
     */
    public void setTimeso(Time timeso) {
        this.timeso = timeso;
    }

    /**
     * @return the timeStamp
     */
    public Timestamp getTimeStamp() {
        return timeStamp;
    }

    /**
     * @param timeStamp the timeStamp to set
     */
    public void setTimeStamp(Timestamp timeStamp) {
        this.timeStamp = timeStamp;
    }

    /**
     * @return the vtime
     */
    public int getVtime() {
        return vtime;
    }

    /**
     * @param vtime the vtime to set
     */
    public void setVtime(int vtime) {
        this.vtime = vtime;
    }

    /**
     * @return the sourceNodeIP
     */
    public int getSourceNodeIP() {
        return sourceNodeIP;
    }

    /**
     * @param sourceNodeIP the sourceNodeIP to set
     */
    public void setSourceNodeIP(int sourceNodeIP) {
        this.sourceNodeIP = sourceNodeIP;
    }

    /**
     * @return the psip
     */
    public String getPsip() {
        return psip;
    }

    /**
     * @param psip the psip to set
     */
    public void setPsip(String psip) {
        this.psip = psip;
    }

    /**
     * @return the destinationNodeIP
     */
    public int getDestinationNodeIP() {
        return destinationNodeIP;
    }

    /**
     * @param destinationNodeIP the destinationNodeIP to set
     */
    public void setDestinationNodeIP(int destinationNodeIP) {
        this.destinationNodeIP = destinationNodeIP;
    }

    /**
     * @return the nextHopId
     */
    public int getNextHopId() {
        return nextHopId;
    }

    /**
     * @param nextHopId the nextHopId to set
     */
    public void setNextHopId(int nextHopId) {
        this.nextHopId = nextHopId;
    }

    /**
     * @return the pnhip
     */
    public String getPnhip() {
        return pnhip;
    }

    /**
     * @param pnhip the pnhip to set
     */
    public void setPnhip(String pnhip) {
        this.pnhip = pnhip;
    }

    /**
     * @return the previousHopId
     */
    public int getPreviousHopId() {
        return previousHopId;
    }

    /**
     * @param previousHopId the previousHopId to set
     */
    public void setPreviousHopId(int previousHopId) {
        this.previousHopId = previousHopId;
    }

    /**
     * @return the pphip
     */
    public String getPphip() {
        return pphip;
    }

    /**
     * @param pphip the pphip to set
     */
    public void setPphip(String pphip) {
        this.pphip = pphip;
    }

        @Override
    public String toString(){
        String out = "";
        out += "Index: " + getIndex() + " NodeID: " + getNodeId() + " NodeIP: " + getNodeIP() + "\n";
        out += "Mode: " + getMode() + " Packet Type: " + getType() + " Packet Length: " + getPacketLength();
        out += " Packet Sequence No.: " + getPacketSequenceNumber() + "\n";
        out += "Message Size: " + getMessageSize() + " Message Sequence No.: " + getMessageSequenceNum() + "\n";
        out += "Packet sent out from source at " + getTimeso().toString();
        out += "Packet was at this node at " + getTimeStamp().toString();
        out += "Validity time: " + getVtime() + " Source IP: " + getPsip() + " Destination IP: " + getDestinationNodeIP() + "\n";
        out += "Next hop ID: " + getNextHopId() + "Next hop IP: " + getNextHopIP() +"\n";
        out += "Previous hop ID: " + getPreviousHopId() + " Previous hop IP: " + getPphip() + "\n";
        out += "TTL: " + getTimeToLive() + " Hop count: " + getHopCount() + "No of Neighbors: " + getNonb() + "\n";
        return out;
    }



    /* to be implemented
     * struct tm timeso;
    time_t unixtimeso;
    struct tm timestamp;
    time_t unixtimestamp;
    int vtime;
     * //Objects
		Node* current;
		Node* next;
		Node* prev;
		Message* message;
     */


}
